package com.moorror.codegenvel.view.window.codegenxrender.view;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.project.Project;
import com.moorror.codegenvel.common.dialog.DialogFormMark;
import com.moorror.codegenvel.db.sqlite.entity.CodeGenXRenderConnect;
import org.apache.commons.lang3.tuple.Pair;

import javax.swing.*;
import java.util.function.Function;

/**
 * @Author jiyanghuang
 * @Date 2024/4/11 23:10
 */
public class MRDialogDatabaseConnection implements DialogFormMark, Disposable {

    private String title;
    private Project project;
    private Function<MRDialogDatabaseConnection, Pair<Boolean, String>> okFun;

    private AddDatabaseConnection addDatabaseConnection;

    public MRDialogDatabaseConnection(String title, Project project, Function<MRDialogDatabaseConnection, Pair<Boolean, String>> okFun) {
        this.title = title;
        this.project = project;
        this.okFun = okFun;
        addDatabaseConnection = new AddDatabaseConnection(project);
    }

    @Override
    public JComponent jComponent() {
        return addDatabaseConnection;
    }

    @Override
    public <T extends DialogFormMark> Function<T, Pair<Boolean, String>> okFun() {
        return (Function<T, Pair<Boolean, String>>) okFun;
    }

    @Override
    public String title() {
        return title;
    }

    @Override
    public void dispose() {

    }

    public void fetchValue(CodeGenXRenderConnect entity){
        addDatabaseConnection.fetchValue(entity);
    }
}
